<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加</title>
    <#assign base=request.contextPath  />
    <base id="base" href="${base}">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, adminUser-scalable=0">
    <link rel="stylesheet" href="${base}/static/win10/component/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${base}/static/win10/css/wangEditor.min.css" media="all">
    <script>
        var base = "${base}";
    </script>
</head>
<body>
<br>
<form class="layui-form " action="">
    <input type="hidden" id="positionId" name="positionId" value="${wechatPosition.positionId!}">

    <#--<div class="layui-form-item">-->
        <#--<label class="layui-form-label">公司ID</label>-->
        <#--<div class="layui-input-block">-->
            <#--<input type="text" id="positionCompanyId1" name="positionCompanyId1"-->
                   <#--value="${wechatPosition.positionCompanyId!}" autocomplete="off" placeholder="请输入公司ID"-->
                   <#--class="layui-input">-->
        <#--</div>-->
    <#--</div>-->

            <div class="layui-form-item">
                <label class="layui-form-label">所属公司</label>
                <div class="layui-input-block">
                    <#--<input type="text" id="paname" name="paname"   autocomplete="off" placeholder="目录名称"-->
                    <#--class="layui-input">-->
                    <select class="my-sle s_change" id="positionCompanyId" name="positionCompanyId" lay-filter="aihao" type="button">
                        <#--<option value="" >写作</option>-->
                        <#--<option value="1">阅读</option>-->
                    </select>
                </div>
            </div>







    <div class="layui-form-item">
        <label class="layui-form-label">区域ID</label>
        <div class="layui-input-block">
            <input type="text" id="positionAreaId" name="positionAreaId" value="${wechatPosition.positionAreaId!}"
                   autocomplete="off" placeholder="请输入区域ID"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">职位区域ID </label>
        <div class="layui-input-block">
            <input type="hidden" value="${wechatPosition.positionAreaId!}" id="companyareaids">

            <div class="layui-input-inline">
                <select name="province" lay-filter="province" id="province">
                    <option value="">请选择省</option>
                </select>
            </div>
            <div class="layui-input-inline" style="display: none;" >
                <select name="city" lay-filter="city" id="city">
                    <option value="">请选择市</option>
                </select>
            </div>
            <div class="layui-input-inline" style="display: none;">
                <select name="area" lay-filter="area"  id="area">
                    <option value="">请选择县/区</option>
                </select>
            </div>
            <div class="layui-input-inline" style="display: none;" >
                <select name="street" lay-filter="street" id="street">
                    <option value="">请选择街道</option>
                </select>
            </div>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">职位类型</label>
        <div class="layui-input-block">
            <input type="hidden" id="positionIndustryId" name="positionIndustryId" value="${wechatPosition.positionIndustryId!}">
            <#--class="layui-input">-->
            <#--<select class="my-sle s_change"  id="pname" name="pname" lay-filter="aihao" type="button">-->

                <div class="layui-input-inline">
                    <select name="industryType" lay-filter="industryType" id="industryType">
                        <option value="">行业类型</option>
                    </select>
                </div>


                <div class="layui-input-inline" style="display: none;" >
                    <select name="industry" lay-filter="industry" id="industry">
                        <option value="">行业</option>
                    </select>
                </div>


                <#--<option value="" >写作</option>-->
                <#--<option value="1">阅读</option>-->
            </select>
        </div>
    </div>



    <#--<div class="layui-form-item">-->
    <#--<label class="layui-form-label">薪资</label>-->
    <#--<div class="layui-input-block">-->
    <#--<input type="text" id="positionSalary" name="positionSalary" value="${wechatPosition.positionSalary!}"  autocomplete="off" placeholder="请输入薪资"-->
    <#--class="layui-input">-->
    <#--</div>-->
    <#--</div>-->

    <div class="layui-form-item">
        <label class="layui-form-label">薪资标准</label>
        <div class="layui-input-block">

            <@dict_tag type="salaryStandard">
            <#--  name 和lay-filter 为实体类 的属性 -->
                <select id="positionSalary" name="positionSalary" lay-filter="positionSalary">
                <option value=""></option>
                <#if dictList?? && dictList?size gt 0>
                    <#list dictList as dict>
                    <#--判断 回显 -->
                        <#if "${dict.dictK}"== "${wechatPosition.positionSalary!}">
                            <option selected value="${dict.dictK}">${dict.dictVal}</option>

                        <#else>
                            <option value="${dict.dictK}">${dict.dictVal}</option>

                        </#if>


                    </#list>



                </#if>
                </select>
            </@dict_tag>

        </div>
    </div>


    <#--<div class="layui-form-item">-->
    <#--<label class="layui-form-label">职位类型ID</label>-->
    <#--<div class="layui-input-block">-->
    <#--<input type="text" id="positionIndustryId" name="positionIndustryId" value="${wechatPosition.positionIndustryId!}"  autocomplete="off" placeholder="请输入职位类型ID"-->
    <#--class="layui-input">-->
    <#--</div>-->
    <#--</div>-->



    <div class="layui-form-item">
        <label class="layui-form-label">职位联系人名字</label>
        <div class="layui-input-block">
            <input type="text" id="positionUsername" name="positionUsername" value="${wechatPosition.positionUsername!}"
                   autocomplete="off" placeholder="请输入职位联系人名字"
                   class="layui-input">
        </div>
    </div>

    <#--<div class="layui-form-item">-->
        <#--<label class="layui-form-label">创建时间</label>-->
        <#--<div class="layui-input-block">-->
            <#--<input type="text" id="poistionCreateTime" name="poistionCreateTime"-->
                   <#--value="${wechatPosition.poistionCreateTime!}" autocomplete="off" placeholder="请输入创建时间"-->
                   <#--class="layui-input">-->
        <#--</div>-->
    <#--</div>-->
    <#--<div class="layui-form-item">-->
        <#--<label class="layui-form-label">职位修改时间</label>-->
        <#--<div class="layui-input-block">-->
            <#--<input type="text" id="poistionUpdateTime" name="poistionUpdateTime"-->
                   <#--value="${wechatPosition.poistionUpdateTime!}" autocomplete="off" placeholder="请输入职位修改时间"-->
                   <#--class="layui-input">-->
        <#--</div>-->
    <#--</div>-->






    <#--<div class="layui-form-item">-->
        <#--<label class="layui-form-label">是否删除 0 正常/1删除</label>-->
        <#--<div class="layui-input-block">-->
            <#--<input type="text" id="poistionIsDelete" name="poistionIsDelete" value="${wechatPosition.poistionIsDelete!}"-->
                   <#--autocomplete="off" placeholder="请输入是否删除 0 正常/1删除"-->
                   <#--class="layui-input">-->
        <#--</div>-->
    <#--</div>-->




            <div class="layui-form-item">
                <label class="layui-form-label">是否关闭职位</label>
                <div class="layui-input-block" id="gender">
                    <input type="radio" name="isDelete" value="0" title="正常" checked>
                    <input type="radio" name="isDelete" value="1" title="关闭">
                </div>
            </div>



    <#--<div class="layui-form-item">-->
        <#--<label class="layui-form-label">职位要求</label>-->
        <#--<div class="layui-input-block">-->
            <#--<input type="text" id="poistionRequirement" name="poistionRequirement"-->
                   <#--value="${wechatPosition.poistionRequirement!}" autocomplete="off" placeholder="请输入职位要求"-->
                   <#--class="layui-input">-->
        <#--</div>-->
    <#--</div>-->






    <div class="layui-form-item">
        <label class="layui-form-label">技能集合标签</label>
        <div class="layui-input-block">
            <@dict_tag type="skillSet">
            <#--  name 和lay-filter 为实体类 的属性 -->
                <#if dictList?? && dictList?size gt 0>
                    <#--定义变量 0 开关 -->
                    <#assign switch="0"/>
                    <#list dictList as dict>
                        <#--拆分数组 数据库里的 集合标签  进行遍历 -->
                        <#list wechatPosition.poistionLabelIds?split(",") as poistionLabelIds  >

                    <#--判断 回显  contains 为集合中是否包含  这个 应该是写==  -->
                        <#if "${poistionLabelIds}"==("${dict.dictK}")>
                            <input  type="checkbox" name="poistionLabelId" value="${dict.dictK}" title="${dict.dictVal}" checked>
                            <#--复制为1 关闭开关-->
                            <#assign switch="1"/>
                            <#break>
                        <#else>

                        </#if>
                    </#list>

                        <#if switch =="0">
                    <#--当为0的时候 -->
                        <input type="checkbox" name="poistionLabelId" value="${dict.dictK}" title="${dict.dictVal}" >
                            <#else>
                            <#--当为1的时候  打开 开关-->
                            <#assign switch="0"/>
                            </#if>
                    </#list>

                </#if>

            </@dict_tag>

        </div>
    </div>








    <div class="layui-form-item">
        <label class="layui-form-label">职位描述</label>
        <div class="layui-input-block">
            <input type="text" id="positionDescribe" name="positionDescribe" value="${wechatPosition.positionDescribe!}"
                   autocomplete="off" placeholder="请输入职位描述"
                   class="layui-input">
        </div>
    </div>







    <div class="layui-form-item">
        <label class="layui-form-label">职位详细地址</label>
        <div class="layui-input-block">
            <input type="text" id="positionAddress" name="positionAddress" value="${wechatPosition.positionAddress!}"
                   autocomplete="off" placeholder="请输入职位详细地址"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">公司电话</label>
        <div class="layui-input-block">
            <input type="text" id="positionPhone" name="positionPhone" value="${wechatPosition.positionPhone!}"
                   autocomplete="off" placeholder="请输入公司电话"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">职位要求</label>

        <div style="width: 80%" id="editors" class="layui-input-block">
            <p>${wechatPosition.poistionRequirement!}</p>
        </div>
    </div>




    <div align="center">
        <button type="button" class="layui-btn" id="submit">保存</button>
    </div>
</form>

<script src="${base}/static/win10/component/layui/layui.js?t=1"></script>
<script src="${base}/static/win10/js/jquery-1.8.3.min.js?t=1"></script>
<script src="${base}/static/win10/js/areaCallBack.js"></script>
<script src="${base}/static/win10/js/wangEditor.min.js?t=1"></script>
<script>

    <#--行业类型 的树状ID  拆分获取-->
    var  positionIndustryId =   $("#positionIndustryId").val();
    // var positionIndustryIdArray = positionIndustryId.split(",");


    var E = window.wangEditor
    // console.log(window.wangEditor,'===')
    var editor = new E('#editors')
    // 或者 var editor = new E( document.getElementById('editor') )
    editor.customConfig.showLinkImg = false
    editor.customConfig.uploadImgShowBase64 = true
    editor.create()

    //保存行业类型和行业信息的
    // var industrys = '';

    layui.use(['form', 'layer'], function () {
        var form = layui.form
            , layer = layui.layer;
        var $form = $('form');

        loadIndustryType();//加载行业


            //监听点击事件
        form.on('select(industryType)', function(data) {
            var  pid = data.value;
            if (pid.length > 0){
                console.log("pid:"+pid)
                loadIndustry(pid);
            }
        })
        form.on('select(industry)', function(data) {
            var  pid = data.value;

        })


        //加载更目录 行业大体
        function loadIndustryType() {
            var formDate = {
                id:0
            }
            $.ajax({
                type: "POST",
                url: base+"/WeChatUser/wechatIndustry/admin/getAllIndustries",
                data: formDate,
                success: function (data) {
                        console.log(data)
                    var clos = data.data;

                    var proHtml='';

                    for (const p in clos) {
                        if (positionIndustryIdArray[0] == clos[p].industryId){
                            proHtml+= '<option selected value="'+clos[p].industryId+'">'+clos[p].industryName+'</option>';
                            loadIndustry(positionIndustryIdArray[0]);
                        }else{
                            proHtml+= '<option value="'+clos[p].industryId+'">'+clos[p].industryName+'</option>';
                        }
                    }
                    $("#industryType").append(proHtml);
                    form.render();//菜单渲染 把内容加载进去
                }
            });
        }


        //加载行业数据
        function loadIndustry(pid) {
            var formDate = {
                id:pid
            }
            $.ajax({
                type: "POST",
                url: base+"/WeChatUser/wechatIndustry/admin/getAllIndustries",
                data: formDate,
                success: function (data) {
                    //console.log(data)
                    var clos = data.data;
                    var cityHtml='<option value="">请选择行业</option>';
                    for (const p in clos) {
                        /*if (positionIndustryIdArray[1] == clos[p].industryId){
                            cityHtml+= '<option selected value="'+clos[p].industryId+'">'+clos[p].industryName+'</option>';

                        }else {
                            cityHtml+= '<option value="'+clos[p].industryId+'">'+clos[p].industryName+'</option>';
                        }*/
                        cityHtml+= '<option value="'+clos[p].industryId+'">'+clos[p].industryName+'</option>';
                    }
                    $form.find('select[name=industry]').html(cityHtml).parent().show();
                    form.render();//菜单渲染 把内容加载进去
                }
            });
        }


        $("input[name=isDelete][value=0]").attr("checked", ${wechatPosition.poistionIsDelete!} == 0 ? true : false);
        $("input[name=isDelete][value=1]").attr("checked", ${wechatPosition.poistionIsDelete!} == 1 ? true : false);


        form.render();

        $(document).ready(function () {
            $.ajax({
                type: "GET",
                url: base + "/WeChatUser/wechatCompany/admin/getCompanyAll",
                success: function (data) {
                    // console.log(data.data, '----')
                    var str = "";
                    for (var i = 0; i < data.data.length; i++) {
                        // var str = "";
                        if (data.data[i].companyId == ${wechatPosition.positionCompanyId!}) {


                            str = "<option selected value=" + data.data[i].companyId + ">" + data.data[i].companyName + "</option>"
                        } else {
                            str = "<option value=" + data.data[i].companyId + ">" + data.data[i].companyName + "</option>"


                        }
                        $("#positionCompanyId").append(str)
                    }
                    //给下拉框赋值 重现渲染
                    layui.form.render("select");
                }
            });

        })










        $(document).ready(function () {

            var formDate = {
                id:0
            }
            $.ajax({
                type: "GET",
                url: base + "/WeChatUser/wechatIndustry/admin/getAllIndustries",
                data: formDate,
                success: function (data) {
                    // console.log(data.data, '----')
                    var str = "";
                    for (var i = 0; i < data.data.length; i++) {
                        // var str = "";
                        if (data.data[i].industryId == ${wechatPosition.positionIndustryId!}) {


                            str = "<option selected value=" + data.data[i].industryId + ">" + data.data[i].industryName + "</option>"
                        } else {
                            str = "<option value=" + data.data[i].industryId + ">" + data.data[i].industryName + "</option>"


                        }
                        $("#pname").append(str)
                    }
                    //给下拉框赋值 重现渲染
                    layui.form.render("select");
                }
            });

        })









        $("#submit").on("click", function () {
            areaids = $("#province").val()+","+$("#city").val()+","+$("#area").val()+","+$("#street").val() ;

            // industrys=$("#industryType").val()+","+$("#industry").val();


            var arr_box = [];
            $('input[type=checkbox]:checked').each(function() {
                arr_box.push($(this).val());
            });
            //数组
            console.log("技能标签:"+arr_box.toString());


            if (check() === false) {
                return;
            }

            var formDate = {
                positionId: $("#positionId").val(),
                positionCompanyId: $("#positionCompanyId").val(),
                positionAreaId: areaids,
                positionSalary: $("#positionSalary").val(),
                positionIndustryId: $("#industry").val(),
                positionUsername: $("#positionUsername").val(),
                // poistionCreateTime: $("#poistionCreateTime").val(),
                // poistionUpdateTime: $("#poistionUpdateTime").val(),
                poistionIsDelete: $('#gender input[name="isDelete"]:checked ').val(),
                poistionRequirement: editor.txt.html(),
                poistionLabelIds: arr_box.toString(),
                positionDescribe: $("#poistionLabelIds").val(),
                positionAddress: $("#positionAddress").val(),
                positionPhone: $("#positionPhone").val()
            }
            $.ajax({
                type: "POST",
                url: base + "/WeChatUser/wechatPosition/admin/editWechatPosition",
                data: formDate,
                success: function (data) {
                    layer.msg(data.message)
                    if (data.code === 200) {
                        window.location.href = base + "/WeChatUser/wechatPosition/admin/main.html"
                    } else {

                    }
                }
            });
        })


        function check() {
            if ($("#positionCompanyId").val().length < 1) {
                layer.msg("请输入公司ID");
                return false;
            }

            console.log("区域ID:" + areaids)
            if (areaids.length < 1) {
                layer.msg("请输入区域ID");
                return false;
            }
            if ($("#positionSalary").val().length < 1) {
                layer.msg("请输入薪资");
                return false;
            }
            if ($("#pname").val().length < 1) {
                layer.msg("请输入职位类型ID");
                return false;
            }
            if ($("#positionUsername").val().length < 1) {
                layer.msg("请输入职位联系人名字");
                return false;
            }
            // if ($("#poistionCreateTime").val().length < 1) {
            //     layer.msg("请输入创建时间");
            //     return false;
            // }
            // if ($("#poistionUpdateTime").val().length < 1) {
            //     layer.msg("请输入职位修改时间");
            //     return false;
            // }
            if ($('#gender input[name="isDelete"]:checked ').val().length < 1) {
                layer.msg("请输入是否删除 0 正常/1删除");
                return false;
            }
            // if ($("#poistionRequirement").val().length < 1) {
            //     layer.msg("请输入职位要求");
            //     return false;
            // }
            // if ($("#poistionLabelIds").val().length < 1) {
            //     layer.msg("请输入标签集合");
            //     return false;
            // }
            if ($("#positionDescribe").val().length < 1) {
                layer.msg("请输入职位描述");
                return false;
            }
            if ($("#positionAddress").val().length < 1) {
                layer.msg("请输入职位详细地址");
                return false;
            }
            if ($("#positionPhone").val().length < 1) {
                layer.msg("请输入公司电话");
                return false;
            }
        }
    });

</script>
</body>
</html>